package com.example.aspectjdemo;

import android.util.Log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;

@Aspect
public class BehaviorAspect {
    //切点,执行com.xiaofan.customcontrol.annotation.BehaviorTrace路径下的注解
    @Pointcut("execution(@com.example.aspectjdemo.BehaviorTrace * *(..))")
    public void annoBaviorTrace() {}
 
    //执行annoBaviorTrace方法
    @Around("annoBaviorTrace()")
    public Object waveJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        BehaviorTrace anno = methodSignature.getMethod().getAnnotation(BehaviorTrace.class);
 
        String functionName = anno.value();
 
        Log.i("wxf","方法："+functionName);
        long begin = System.currentTimeMillis();
        //方法执行
        Object reuslt= joinPoint.proceed();
 
        long duration = System.currentTimeMillis() - begin;
 
        Log.i("wxf","方法耗时："+duration+" ms");
        return reuslt;
    }
}
